package com.guang.countdownlatch;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;

/**
 * @author lg
 * @Description 使用CountDownLatch
 * @date 2022/10/17 11:33
 */
public class CountDownLatchOne {

    private static Logger logger = LoggerFactory.getLogger(CountDownLatchOne.class);

    static CountDownLatch countDownLatch = new CountDownLatch(5);

    public static void main(String[] args) {
        logger.info("main start");
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                logger.info("start");
                logger.info("当前线程名称是：{}",Thread.currentThread().getName());
                logger.info("end");
                countDownLatch.countDown();
            },"t"+(i+1)).start();
        }
        try {
            // 阻塞队列中进行等待
            countDownLatch.await();
            logger.info("main end");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
